package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.base.model.User;
import com.yunfeisoft.business.dao.inter.ElderApprovalResultDao;
import com.yunfeisoft.business.model.Elder;
import com.yunfeisoft.business.model.ElderApprovalResult;
import com.yunfeisoft.common.base.BaseDao;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Auther: r.cheng
 * @Date: 2020/4/1 11:07
 * @Description: 老人入院审批Dao实现
 * @Version: 1.0
 */
@Repository
public class ElderApprovalResultDaoImpl extends BaseDaoImpl<ElderApprovalResult, String> implements ElderApprovalResultDao {

    /**
     * 查询审批列表
     * @param elderId
     * @return
     */
    @Override
    public List<ElderApprovalResult> queryByElderId(String elderId) {
        if (StringUtils.isBlank(elderId)) {
            return new ArrayList<>();
        }
        SelectBuilder builder = getSelectBuilder("r");
        builder.column("u.name as username")
                .leftJoin(User.class).alias("u")
                .on("r.createId = u.id").build();
        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("elderId", elderId);
        wb.setOrderByWithDesc("createTime");
        return query(builder.getSql(), wb);
    }

}
